package sys.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import sys.dao.StudentDao;
import sys.dao.TeacherDao;
import sys.entity.*;
import sys.service.StudentService;
import java.util.List;
import java.util.Map;

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentDao studentDao;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Autowired
    private TeacherDao teacherDao;

    @Override
    public void addD(Integer[] checkitemIds, Student student) {
        studentDao.addD(student);
        stringRedisTemplate.opsForList().leftPush("学生ID",student.getId().toString());
        for (Integer tid : checkitemIds) {
            studentDao.addXidAndUid(student.getId(),tid);
        }
    }

    @Override
    public PageInfo findPage(Integer pageIndex, Map serachMap) {
        PageHelper.startPage(pageIndex,2);
        List<Student> list=studentDao.findPages(serachMap);
        return new PageInfo(list);
    }

    @Override
    public List<Teacher> findTea() {
        return teacherDao.findTea();
    }

    @Override
    public void editStu(Integer[] checkitemIds, Student student) {
        studentDao.delBySid(student.getId());
        studentDao.editStu(student);
        for (Integer tid : checkitemIds) {
            studentDao.addXidAndUid(student.getId(),tid);
        }
    }

    @Override
    public Student findById(Integer id) {
        return studentDao.findById(id);
    }

    @Override
    public List<Integer> findTidBySid(Integer id) {
        return studentDao.selectTidBySid(id);
    }
}



